package com.lz.wsy.oss2;


import com.lz.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;


/**
 * 这是一个类
 *
 * @author wzy
 * @date 2021/6/1  10:09
 */
@RequestMapping("/file")
@Controller
public class UploadController {

    @Autowired
    private OssUtils ossUtils;

    @ApiOperation(value = "文件上传")
    @PostMapping("/upload")
    @ResponseBody
    public Result uploadFileSample(@RequestParam(value = "file",required = false) MultipartFile file) {
        Result result = null;
        if (!file.isEmpty()) {
            result = ossUtils.uploadFile(file);
        }else {
            return Result.error("文件为空");
        }
        return Result.success(result);
    }

}
